package fr.minuskube.inv.opener;

import com.google.common.base.Preconditions;
import fr.minuskube.inv.InventoryManager;
import fr.minuskube.inv.SmartInventory;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;

public class ChestInventoryOpener implements InventoryOpener {
  public Inventory open(SmartInventory inv, Player player) {
    Preconditions.checkArgument((inv.getColumns() == 9), "The column count for the chest inventory must be 9, found: %s.", new Object[] { Integer.valueOf(inv.getColumns()) });
    Preconditions.checkArgument((inv.getRows() >= 1 && inv.getRows() <= 6), "The row count for the chest inventory must be between 1 and 6, found: %s", new Object[] { Integer.valueOf(inv.getRows()) });
    InventoryManager manager = inv.getManager();
    Inventory handle = Bukkit.createInventory((InventoryHolder)player, inv.getRows() * inv.getColumns(), inv.getTitle());
    fill(handle, manager.getContents(player).get());
    player.openInventory(handle);
    return handle;
  }
  
  public boolean supports(InventoryType type) {
    return (type == InventoryType.CHEST || type == InventoryType.ENDER_CHEST);
  }
}
